function isrepeat(ary) {
	var s=ary.join(",")+",";
	for(var i=0;i<ary.length;i++) {
		if(s.replace(ary[i]+",","").indexOf(ary[i]+",")>-1) {
			return true;
		}
	}return false;
}
function array_has(array,val) {
	var i;
	for(i=1;i<array.length;i++) {
		if(array[i]==val) {
			return false;
		}
	}return true;
}
function filter(a1,a2) {
	var myAry=[];
	for(var i=1;i<a1.length;i++) {
		if(array_has(a2,a1[i]))myAry.push(a1[i]);
	}for(var i=1;i<a2.length;i++) {
		if(array_has(a1,a2[i]))myAry.push(a2[i]);
	}return myAry;
}
function loadtext(thisid,thistext) {
	var o=document.getElementById(thisid);
	o.onblur=function () {
		if(o.value=="") {
			o.value=thistext;
			$("#"+thisid).attr("class","init-input");
		}else if(o.value!==""&&o.value!==thistext) {
			$("#"+thisid).attr("class","step-input");
		}
	}o.onfocus=function () {
		if(o.value==thistext) {
			o.value='';
			$("#"+thisid).attr("class","step-input");
		}
	}o.onblur();
}
function loadtextyidi(thisid,thistext) {
	var o=document.getElementById(thisid);
	o.onblur=function () {
		if(o.value=="") {
			o.value=thistext;
			$("#"+thisid).attr("class","inityidi-input");
		}else if(o.value!==""&&o.value!==thistext) {
			$("#"+thisid).attr("class","stepyidi-input");
		}
	}o.onfocus=function () {
		if(o.value==thistext) {
			o.value='';
			$("#"+thisid).attr("class","stepyidi-input");
		}
	}o.onblur();
}
function loadtext2(thisid,thistext) {
	var o=document.getElementById(thisid);
	o.onblur=function () {
		if(o.value=="") {
			o.value=thistext;
			$("#"+thisid).attr("class","init-inputname");
		}else if(o.value!==""&&o.value!==thistext) {
			$("#"+thisid).attr("class","name-input");
		}
	}o.onfocus=function () {
		if(o.value==thistext) {
			o.value='';
			$("#"+thisid).attr("class","name-input");
		}
	}o.onblur();
}
function loadtext1(thisid,thistext) {
	var o=document.getElementById(thisid);
	o.onblur=function () {
		if(o.value=="") {
			o.value=thistext;
			$("#"+thisid).attr("class","init-input");
		}else if(o.value!==""&&o.value!==thistext) {
			$("#"+thisid).attr("class","step-input");
		}
	}o.onfocus=function () {
		if(o.value==thistext) {
			o.value='';
			$("#"+thisid).attr("class","step-input");
		}
	}
}
function submitmember(url) {
	$.ajax({
		type:"POST",url:url,dataType:"xml",error:function (xml) {
			$(xml).find('Error').each(function () {
				var errortext=$(this).attr('msg');
				alert(errortext);
			});
		},success:function (xml) {
			var stat=$(xml).find("rsp").attr('stat');
			if(stat=="ok") {
				//show_message("success",msg.submitSuccess);
				alert(msg.submitSuccess);
				window.location.reload();
			}else if(stat=="restart"||stat=="reboot") {
				//show_message("success",msg.restartSuccess);
				alert(msg.restartSuccess);
				window.location.reload();
			}else if(stat=="fail") {
				//show_message("err",msg.actionFail);
				alert(msg.actionFail);
			}
		}
	});
}
function submitvalue(url,flag) {
	$.ajax({
		type:"POST",url:'xml',data:url,dataType:"xml",error:function (xml) {
			$(xml).find('Error').each(function () {
				var errortext=$(this).attr('msg');
				alert(errortext);
			});
		},success:function (xml) {
			if(flag=="1") {
				var stat=$(xml).find("rsp").attr('stat');
				if(stat=="ok") {
					window.location.href="tie_general.htm";
				}else if(stat=="restart"||stat=="reboot") {
					//show_message("success",msg.restartSuccess);
					alert(msg.restartSuccess);
					window.location.href="tie_general.htm";
				}else if(stat=="fail") {
					//show_message("err",msg.actionFail);
					alert(msg.actionFail);
				}
			}else if(flag=="2") {
				var stat=$(xml).find("rsp").attr('stat');
				if(stat=="ok") {
					window.location.href="tie_manage.htm";
				}else if(stat=="restart"||stat=="reboot") {
					//show_message("success",msg.restartSuccess);
					alert(msg.restartSuccess);
					window.location.href="tie_manage.htm";
				}else if(stat=="fail") {
					//show_message("err",msg.actionFail);
					alert(msg.actionFail);
				}
			}else if(flag=="8") {
				var stat=$(xml).find("rsp").attr('stat');
				if(stat=="ok"||stat=="restart"||stat=="reboot") {
					window.location.href="tietrunk_old.htm";
				}else if(stat=="fail") {
					//show_message("err",msg.actionFail);
					alert(msg.actionFail);
				}
			}else if(flag=="9") {
				var stat=$(xml).find("rsp").attr('stat');
				if(stat=="ok"||stat=="restart"||stat=="reboot") {
					window.location.href="tiet_role.htm";
				}else if(stat=="fail") {
					//show_message("err",msg.actionFail);
					alert(msg.actionFail);
				}
			}else if(flag=="3") {
				var stat=$(xml).find("rsp").attr('stat');
				if(stat=="ok") {
					//show_message("success",msg.submitSuccess);
					alert(msg.submitSuccess);
					window.location.reload();
				}else if(stat=="restart"||stat=="reboot") {
					//show_message("success",msg.restartSuccess);
					alert(msg.restartSuccess);
					window.location.reload();
				}else if(stat=="fail") {
					//show_message("err",msg.actionFail);
					alert(msg.actionFail);
				}
			}else if(flag=="5") {
				var stat=$(xml).find("rsp").attr('stat');
				if(stat=="ok") {
					//show_message("success",msg.submitSuccess);
					alert(msg.submitSuccess);
					window.location.reload();
				}else if(stat=="restart"||stat=="reboot") {
					//show_message("success",msg.restartSuccess);
					alert(msg.restartSuccess);
					window.location.href="tietrunk.htm";
				}else if(stat=="fail") {
					//show_message("err",msg.actionFail);
					alert(msg.actionFail);
				}
			}else if(flag=="4") {
				var stat=$(xml).find("rsp").attr('stat');
				if(stat=="ok") {
					//show_message("err",tietrunkjs.cue1);
					alert(tietrunkjs.cue1);
					window.location.reload();
				}else if(stat=="restart"||stat=="reboot") {
					//show_message("err",tietrunkjs.cue1);
					alert(tietrunkjs.cue1);
					window.location.reload();
				}else if(stat=="fail") {
					//show_message("err",msg.actionFail);
					alert(msg.actionFail);
				}
			}else if(flag=="6") {
				var stat=$(xml).find("rsp").attr('stat');
				if(stat=="ok") {
					//show_message("success",msg.submitSuccess);
					alert(msg.submitSuccess);
					window.location.href="tie_general.htm";
				}else if(stat=="restart"||stat=="reboot") {
					//show_message("success",msg.restartSuccess);
					alert(msg.restartSuccess);
					window.location.href="tie_general.htm";
				}else if(stat=="fail") {
					var errortext=$(xml).find("rsp").text();
					alert(errortext);
				}
			}else if(flag=="7") {
				var stat=$(xml).find("rsp").attr('stat');
				if(stat=="ok"||stat=="reboot"||stat=="restart") {
					//show_message("err",tietrunkjs.cue2);
					alert(tietrunkjs.cue2);
				}else {
					var code=$(xml).find("Error").attr("code");
					if(code=="4") {
						//show_message("err",msg.cannotModify1);
						alert(msg.cannotModify1);
					}else if(code=="5") {
						gotologin();
					}else {
						//show_message("err",msg.actionFail);
						alert(msg.actionFail);
					}
				}
			}
		}
	});
}
function getmember() {
	DataRequest("get_json","&id=800&id=488",function(data){
  	$("[name=id800]").attr("value",data["id800"]);
  	$("[name=id800]").attr("value",data["id488"]);
   });
	
	var url='/xml?method=gw.config.get&id=476&id=361&tmp='+Math.random();
	$.get(url,function (data) {
		var stat=$(data).find('rsp').attr("stat");
		if(stat=="fail") {
			$(data).find('Error').each(function () {
				var code=$(this).attr('code');
				if(code==4) {
					//show_message("err",msg.cannotModify1);
					alert(msg.cannotModify1);
				}else if(code==5) {
					gotologin();
				}
			});
		}else {
			var tietrunk_number='';
			$(data).find("item").each(function () {
				if($(this).attr("id")=="361") {
					tietrunk_number=$(this).attr("value");
				}else {
					var value476=$(this).attr("value");
					if(value476!=="5060") {
						$("#msg476").html(tietrunkjs.cue3+value476+tietrunkjs.cue4+value476);
					}
				}
			});
			var gettext='';
			for(var i=1;i<=tietrunk_number;i++) {
				gettext+='&line_id='+i+'&id=810&id=815&id=812';
			}var geturl='/xml?method=gw.config.get'+gettext+'&tmp='+Math.random();
			$.get(geturl,function (data) {
				var stat=$(data).find('rsp').attr("stat");
				if(stat=="fail") {
					$(data).find('Error').each(function () {
						var code=$(this).attr('code');
						if(code==4) {
							//show_message("err",msg.cannotModify1);
							alert(msg.cannotModify1);
						}else if(code==5) {
							gotologin();
						}
					});
				}else {
					var tablehtml='';
					var array810=new Array();
					var array815=new Array();
					var array812=new Array();
					$(data).find("item").each(function () {
						var line_id='';
						if(tietrunk_number=="1") {
							line_id=$(data).find("config").attr("line_id");
						}else {
							line_id=$(this).attr("line_id");
						}if($(this).attr("id")=="810") {
							array810[line_id]=$(this).attr("value");
						}else if($(this).attr("id")=="815") {
							array815[line_id]=$(this).attr("value");
						}else if($(this).attr("id")=="812") {
							array812[line_id]=$(this).attr("value");
						}
					});
					for(var j=1;j<=tietrunk_number;j++) {
						if(j=="1") {
							tablehtml+='<tr id="tr_'+j+'"><td class="td_tiet">&nbsp;'+array810[j]+'</td><td class="td_tiet">&nbsp;<input type="text" id="siteid_'+j+'" name="siteid" value="'+array812[j]+'" class="line-input"/></td><td class="td_tiet">&nbsp;'+tietrunkjs.cue5+'</td><td class="td_tiet">&nbsp;</td></tr>';
						}else {
							tablehtml+='<tr id="tr_'+j+'"><td class="td_tiet">&nbsp;<input type="text" id="tie_'+j+'" name="text" value="'+array810[j]+'" class="step-input"/></td><td class="td_tiet">&nbsp;<input type="text" id="siteid_'+j+'" name="siteid" value="'+array812[j]+'" class="line-input"/></td><td class="td_tiet">&nbsp;<input type="text" id="name_'+j+'" name="bieming" value="'+array815[j]+'" class="name-input"/></td><td class="td_tiet"><img src="delete.gif" width="14" height="13"/><a href="#" name="delete" id="delete_'+j+'">'+tietrunkjs.cue6+'</a></td></tr>';
						}
					}$("#members").html(tablehtml);
					$("[name=delete]").click(function () {
						var numbers=$(this).attr("id").split("_")[1];
						$("#tr_"+numbers).hide();
						$("#tie_"+numbers).attr("value","");
						$("#name_"+numbers).attr("value","");
						$("#siteid_"+numbers).attr("value","");
						var setstr="&line_id="+numbers+"&id810=";
						var urls="xml?method=gw.config.set"+setstr+"&tmp="+Math.random();
						submitmember(urls);
						getmember();
					});
					$("[name=add_member]").click(function () {
						var total=1;
						$("#members").find("tr").each(function () {
							total++;
						});
						var setstr="xml?method=gw.config.set&line_id="+total+"&id810=&id811=&id812=&id814=&id815=&id816=&id817=";
						$.ajax({
							type:"POST",url:setstr,dataType:"xml",error:function (xml) {
								$(xml).find('Error').each(function () {
									var errortext=$(this).attr('msg');
									alert(errortext);
								});
							},success:function (xml) {
								var stat=$(xml).find("rsp").attr('stat');
								if(stat=="ok"||stat=="reboot"||stat=="restart") {
									var names=$("#tie_"+(total-1)).val();
									var tabletietrunk='<tr id="tr_'+total+'"><td class="td_tiet">&nbsp;<input type="text" name="text" id="tie_'+total+'" class="step-input" value=""/></td><td class="td_tiet">&nbsp;<input type="text" id="siteid_'+total+'" name="siteid" value="" class="line-input"/></td><td class="td_tiet">&nbsp;<input type="text" id="name_'+total+'" name="bieming" value="" class="name-input"/></td><td class="td_tiet"><img src="delete.gif" width="14" height="13"/><a href="#" name="delete" id="delete_'+total+'">'+tietrunkjs.cue6+'</a></td></tr>';
									$("#members").append(tabletietrunk);
									loadtext("tie_"+total,tietrunkjs.cue7);
									loadtext2("name_"+total,tietrunkjs.cue8);
								}
							}
						});
						$("[name=delete]").click(function () {
							var numbers=$(this).attr("id").split("_")[1];
							$("#tr_"+numbers).hide();
							$("#tie_"+numbers).attr("value","");
							$("#name_"+numbers).attr("value","");
							$("#siteid_"+numbers).attr("value","");
							var setstr="&line_id="+numbers+"&id810=";
							var urls="xml?method=gw.config.set"+setstr+"&tmp="+Math.random();
							submitmember(urls);
							getmember();
						});
					});
					$("[name=submit_member]").click(function () {
						var settext='&id800='+$("[name=id800]").val();
						if($("#radio488_1").attr("checked")) {
							settext+="&id488=0";
						}else if($("#radio488_2").attr("checked")) {
							settext+="&id488=1";
						}var flag='';
						var flagname='';
						var s=0;
						var namestr=new Array();
						settext+="&line_id=1&id812="+$("#siteid_1").val();
						$("#members").find("tr").each(function () {
							var thisid=$(this).attr("id").split("_")[1];
							if(thisid!="1") {
								if($("#tie_"+thisid).val()!==tietrunkjs.cue7&&$("#tie_"+thisid).val()!=="") {
									settext+="&line_id="+thisid+"&id810="+$("#tie_"+thisid).val();
								}else {
									flagname="false";
									settext+="&line_id="+thisid+"&id810=";
								}if($("#siteid_"+thisid).val()!=="") {
									settext+="&line_id="+thisid+"&id812="+$("#siteid_"+thisid).val();
								}else {
									flag='false';
									settext+="&line_id="+thisid+"&id812=";
								}if($("#name_"+thisid).val()!==tietrunkjs.cue8&&$("#name_"+thisid).val()!=="") {
									settext+="&line_id="+thisid+"&id815="+$("#name_"+thisid).val();
									namestr[s]=$("#name_"+thisid).val();
									s++;
								}else {
									flag='false';
									settext+="&line_id="+thisid+"&id815=";
								}
							}
						});
						if(flag=="false"&&flagname!="false") {
							//show_message("err",tietrunkjs.cue9);
							alert(tietrunkjs.cue9);
						}else {
							var url="xml?method=gw.config.set"+settext+"&tmp="+Math.random();
							submitmember(url);
						}
					});
				}
			});
		}
	});
}
function getTieStatus() {
	var url='/xml?method=gw.config.get&id=800&id=361&tmp='+Math.random();
	$.get(url,function (data) {
		var stat=$(data).find('rsp').attr("stat");
		if(stat=="fail") {
			$(data).find('Error').each(function () {
				var code=$(this).attr('code');
				if(code==4) {
					//show_message("err",msg.cannotModify1);
					alert(msg.cannotModify1);
				}else if(code==5) {
					gotologin();
				}
			});
		}else {
			var tietrunk_number='';
			var refreshtime='';
			$(data).find("item").each(function () {
				if($(this).attr("id")=="800") {
					refreshtime=$(this).attr("value");
					refreshtime=refreshtime*3;
				}else if($(this).attr("id")=="361") {
					tietrunk_number=$(this).attr("value");
				}
			});
			var gettext='';
			for(var i=1;i<=tietrunk_number;i++) {
				gettext+='&line_id='+i+'&id=810&id=820&id=812&id=818&id=815';
			}var geturl='/xml?method=gw.config.get'+gettext+'&tmp='+Math.random();
			$.get(geturl,function (data) {
				var stat=$(data).find('rsp').attr("stat");
				if(stat=="fail") {
					$(data).find('Error').each(function () {
						var code=$(this).attr('code');
						if(code==4) {
							//show_message("err",msg.cannotModify1);
							alert(msg.cannotModify1);
						}else if(code==5) {
							gotologin();
						}
					});
				}else {
					var array810=new Array();
					var array820=new Array();
					var array812=new Array();
					var array818=new Array();
					var array815=new Array();
					$(data).find("item").each(function () {
						var line_id='';
						if(tietrunk_number=="1") {
							line_id=$(data).find("config").attr("line_id");
						}else {
							line_id=$(this).attr("line_id");
						}if($(this).attr("id")=="810") {
							array810[line_id]=$(this).attr("value");
						}
					});
					$(data).find("item").each(function () {
						var line_id='';
						if(tietrunk_number=="1") {
							line_id=$(data).find("config").attr("line_id");
						}else {
							line_id=$(this).attr("line_id");
						}if($(this).attr("id")=="820") {
							if(checkDomain(array810[line_id])) {
								var value820=parseInt($(this).attr("value"));
								if(value820>=refreshtime) {
									array820[line_id]='<img src="error.jpg" border="0"/><span style="padding-left:10px;">&#160;</span><font style="color:red;">'+msd(value820)+tietrunkjs.cue10+'</font>';
								}else if(value820=="-1") {
									array820[line_id]="--";
								}else if(value820=="0") {
									array820[line_id]=tietrunkjs.cue11;
								}else {
									array820[line_id]=msd(value820)+tietrunkjs.cue10;
								}
							}else {
								array820[line_id]="--";
							}
						}else if($(this).attr("id")=="812") {
							array812[line_id]=$(this).attr("value");
						}else if($(this).attr("id")=="818") {
							array818[line_id]=$(this).attr("value");
						}else if($(this).attr("id")=="815") {
							if($(this).attr("value")!=="") {
								array815[line_id]=$(this).attr("value");
							}else {
								array815[line_id]='';
							}
						}
					});
					var tablehtml='';
					for(var j=1;j<=tietrunk_number;j++) {
						if(j==1) {
							tablehtml+='<tr id="tr_'+j+'"><td class="td_tiet">&nbsp;'+array810[j]+'</td><td class="td_tiet">&nbsp;'+tietrunkjs.cue5+'</td><td class="td_tiet">&nbsp;'+array820[j]+'</td><td class="td_tiet">&nbsp;'+array812[j]+'</td><td class="td_tiet">&nbsp;'+array818[j]+'</td></tr>';
						}else {
							tablehtml+='<tr id="tr_'+j+'"><td class="td_tiet">&nbsp;'+array810[j]+'</td><td class="td_tiet">&nbsp;'+array815[j]+'</td><td class="td_tiet">&nbsp;'+array820[j]+'</td><td class="td_tiet">&nbsp;'+array812[j]+'</td><td class="td_tiet">&nbsp;'+array818[j]+'</td></tr>';
						}
					}$("#tietrunk_body").html(tablehtml);
				}
			});
		}
	});
}
function geterrorinfo() {
	var url='/xml?method=gw.config.get&id=800&id=361&tmp='+Math.random();
	$.get(url,function (data) {
		var stat=$(data).find('rsp').attr("stat");
		if(stat=="fail") {
			$(data).find('Error').each(function () {
				var code=$(this).attr('code');
				if(code==4) {
					//show_message("err",msg.cannotModify1);
					alert(msg.cannotModify1);
				}else if(code==5) {
					gotologin();
				}
			});
		}else {
			var tietrunk_number='';
			var refreshtime='';
			$(data).find("item").each(function () {
				if($(this).attr("id")=="800") {
					refreshtime=$(this).attr("value");
					refreshtime=refreshtime*3;
				}else if($(this).attr("id")=="361") {
					tietrunk_number=$(this).attr("value");
				}
			});
			var gettext='';
			for(var i=1;i<=tietrunk_number;i++) {
				gettext+='&line_id='+i+'&id=810&id=820&id=812&id=818';
			}var geturl='/xml?method=gw.config.get'+gettext+'&tmp='+Math.random();
			$.get(geturl,function (data) {
				var stat=$(data).find('rsp').attr("stat");
				if(stat=="fail") {
					$(data).find('Error').each(function () {
						var code=$(this).attr('code');
						if(code==4) {
							//show_message("err",msg.cannotModify1);
							alert(msg.cannotModify1);
						}else if(code==5) {
							gotologin();
						}
					});
				}else {
					var array810=new Array();
					var array820=new Array();
					var array820_s=new Array();
					var array812=new Array();
					var array818=new Array();
					$(data).find("item").each(function () {
						var line_id='';
						if(tietrunk_number=="1") {
							line_id=$(data).find("config").attr("line_id");
						}else {
							line_id=$(this).attr("line_id");
						}if($(this).attr("id")=="810") {
							array810[line_id]=$(this).attr("value");
						}
					});
					$(data).find("item").each(function () {
						var line_id='';
						if(tietrunk_number=="1") {
							line_id=$(data).find("config").attr("line_id");
						}else {
							line_id=$(this).attr("line_id");
						}if($(this).attr("id")=="820") {
							if(checkDomain(array810[line_id])) {
								var value820=parseInt($(this).attr("value"));
								array820_s[line_id]=parseInt($(this).attr("value"));
								if(value820>=refreshtime) {
									array820[line_id]='<img src="error.jpg" border="0"/><span style="padding-left:10px;">&#160;</span><font style="color:red;">'+msd(value820)+tietrunkjs.cue10+'</font>';
								}else if(value820=="-1") {
									array820[line_id]="--";
								}else {
									array820[line_id]=msd(value820)+tietrunkjs.cue10;
								}
							}else {
								array820[line_id]="--";
							}
						}else if($(this).attr("id")=="812") {
							array812[line_id]=$(this).attr("value");
						}else if($(this).attr("id")=="818") {
							array818[line_id]=$(this).attr("value");
						}
					});
					var tablehtml='';
					for(var j=1;j<=tietrunk_number;j++) {
						if(array820_s[j]>=refreshtime) {
							if(j==1) {
								tablehtml+='<tr id="tr_'+j+'"><td class="td_tiet">&nbsp;'+array810[j]+'</td><td class="td_tiet">&nbsp;'+array820[j]+'</td><td class="td_tiet">&nbsp;<input type="text" name="text" id="text_'+j+'" class="step-input" value="'+array818[j]+'"/></td></tr>';
							}else {
								tablehtml+='<tr id="tr_'+j+'"><td class="td_tiet">&nbsp;'+array810[j]+'</td><td class="td_tiet">&nbsp;'+array820[j]+'</td><td class="td_tiet">&nbsp;<input type="text" name="text" id="text_'+j+'" class="step-input" value="'+array818[j]+'"/></td></tr>';
							}
						}
					}$("#fix_body").html(tablehtml);
					$("[name=submit_ip]").click(function () {
						var settext='';
						$("#tietrunk_body").find("tr").each(function () {
							var thisid=$(this).attr("id").split("_")[1];
							settext+="&line_id="+thisid+"&id818="+$("#text_"+thisid).val();
						});
						var url="method=gw.config.set"+settext+"&tmp="+Math.random();
						submitvalue(url,"3");
					});
				}
			});
		}
	});
}
function getprefix() {
	var url='/xml?method=gw.config.get&id=361&id=673&id=800&tmp='+Math.random();
	$.get(url,function (data) {
		var stat=$(data).find('rsp').attr("stat");
		if(stat=="fail") {
			$(data).find('Error').each(function () {
				var code=$(this).attr('code');
				if(code==4) {
					//show_message("err",msg.cannotModify1);
					alert(msg.cannotModify1);
				}else if(code==5) {
					gotologin();
				}
			});
		}else {
			var tietrunk_number=0;
			var refreshtime='';
			var roles='';
			$(data).find("item").each(function () {
				if($(this).attr("id")=="361") {
					tietrunk_number=$(this).attr("value");
				}else if($(this).attr("id")=="800") {
					refreshtime=parseInt($(this).attr("value"));
				}else if($(this).attr("id")=="673") {
					roles=parseInt($(this).attr("value"));
				}
			});
			if(roles=="1"||roles=="3") {
				$.ajax({
					type:"POST",url:'xml?method=gw.command.set&action=tie_sync&tmp='+Math.random(),dataType:"xml",async:false,error:function (xml) {
						$(xml).find('Error').each(function () {
							var errortext=$(this).attr('msg');
							alert(errortext);
						});
					},success:function (xml) {
						var rspstat=$(xml).find("rsp").attr("stat");
						if(rspstat=="ok"||rspstat=="reboot"||rspstat=="restart") {
							prefixmethod(tietrunk_number,refreshtime);
						}else {
							var errorcode=$(xml).find('Error').attr('code');
							if(errorcode=='5') {
								gotologin();
							}
						}
					}
				});
			}else {
				prefixmethod(tietrunk_number,refreshtime);
			}
		}
	});
}
function prefixmethod(tietrunk_number,refreshtime) {
	var gettext='';
	for(var i=1;i<=tietrunk_number;i++) {
		gettext+='&line_id='+i+'&id=810&id=812&id=815&id=820';
	}var geturl='/xml?method=gw.config.get'+gettext+'&tmp='+Math.random();
	$.get(geturl,function (data) {
		var stat=$(data).find('rsp').attr("stat");
		if(stat=="fail") {
			$(data).find('Error').each(function () {
				var code=$(this).attr('code');
				if(code==4) {
					//show_message("err",msg.cannotModify1);
					alert(msg.cannotModify1);
				}else if(code==5) {
					gotologin();
				}
			});
		}else {
			var array810=new Array();
			var array812=new Array();
			var array815=new Array();
			var array820=new Array();
			$(data).find("item").each(function () {
				var line_id='';
				if(tietrunk_number=="1") {
					line_id=$(data).find("config").attr("line_id");
				}else {
					line_id=$(this).attr("line_id");
				}if($(this).attr("id")=="810") {
					array810[line_id]=$(this).attr("value");
				}
			});
			$(data).find("item").each(function () {
				var line_id='';
				if(tietrunk_number=="1") {
					line_id=$(data).find("config").attr("line_id");
				}else {
					line_id=$(this).attr("line_id");
				}if($(this).attr("id")=="812") {
					array812[line_id]=$(this).attr("value");
				}else if($(this).attr("id")=="820") {
					if(checkDomain(array810[line_id])) {
						if(line_id==1) {
							array820[line_id]=1;
						}else {
							var value820=parseInt($(this).attr("value"));
							if(value820>=refreshtime) {
								array820[line_id]=0;
							}else if(value820=="-1") {
								array820[line_id]=0;
							}else if(value820=="0") {
								array820[line_id]=1;
							}else {
								array820[line_id]=1;
							}
						}
					}else {
						array820[line_id]=1;
					}
				}else if($(this).attr("id")=="815") {
					if(line_id==1) {
						array815[line_id]=tietrunkjs.cue5;
					}else {
						if($(this).attr("value")!=='') {
							array815[line_id]=$(this).attr("value");
						}else {
							array815[line_id]='';
						}
					}
				}
			});
			var tablehtml='';
			var readhtml='';
			for(var j=1;j<=tietrunk_number;j++) {
				if(array820[j]==1) {
					tablehtml+='<tr id="tr_'+j+'"><td class="td_tiet">&nbsp;'+array810[j]+'</td><td class="td_tiet">&nbsp;'+array815[j]+'</td><td class="td_tiet">&nbsp;<input type="text" name="text" id="text_'+j+'" class="line-input" value="'+array812[j]+'"/></td></tr>';
					readhtml+='<tr id="tr_'+j+'"><td class="td_tiet">&nbsp;'+array810[j]+'</td><td class="td_tiet">&nbsp;'+array815[j]+'</td><td class="td_tiet">&nbsp;'+array812[j]+'&nbsp;</td></tr>';
				}else if(array820[j]==0) {
					tablehtml+='<tr id="tr_'+j+'"><td class="td_tiet">&nbsp;<font style="color:#D5D5D5;">'+array810[j]+'</font><td class="td_tiet">&nbsp;<font style="color:#D5D5D5;">'+array815[j]+'</font></td><td class="td_tiet">&nbsp;<input type="text" name="text" id="text_'+j+'" class="line-input" value="'+array812[j]+'"/></td></tr>';
					readhtml+='<tr id="tr_'+j+'"><td class="td_tiet">&nbsp;<font style="color:#D5D5D5;">'+array810[j]+'</font><td class="td_tiet">&nbsp;<font style="color:#D5D5D5;">'+array815[j]+'</font></td><td class="td_tiet">&nbsp;<font style="color:#D5D5D5;">'+array812[j]+'</font>&nbsp;</td></tr>';
				}
			}$("#prefix_number").html(tablehtml);
			$("#read_number").html(readhtml);
			$("[name=submit_idnumber]").click(function () {
				var settext='';
				var flag='';
				var s=0;
				var numberstr=new Array();
				$("#prefix_number").find("tr").each(function () {
					var thisid=$(this).attr("id").split("_")[1];
					if(!isNaN($("#text_"+thisid).val())&&$("#text_"+thisid).val().length<=5) {
						settext+="&line_id="+thisid+"&id812="+$("#text_"+thisid).val();
						numberstr[s]=$("#text_"+thisid).val();
						s++;
					}else if($("#text_"+thisid).val()=="--") {
						settext+="&line_id="+thisid+"&id812="+$("#text_"+thisid).val();
					}else {
						flag="false";
					}
				});
				if(flag=="false") {
					//show_message("err",tietrunkjs.cue12);
					alert(tietrunkjs.cue12);
				}else if(isrepeat(numberstr)) {
					//show_message("err",tietrunkjs.cue13);
					alert(tietrunkjs.cue13);
				}else {
					var url="method=gw.config.set"+settext+"&tmp="+Math.random();
					submitvalue(url,"3");
				}
			});
		}
	});
}
function getziyuan() {
	var url='/xml?method=gw.config.get&id=361&tmp='+Math.random();
	$.get(url,function (data) {
		var stat=$(data).find('rsp').attr("stat");
		if(stat=="fail") {
			$(data).find('Error').each(function () {
				var code=$(this).attr('code');
				if(code==4) {
					//show_message("err",msg.cannotModify1);
					alert(msg.cannotModify1);
				}else if(code==5) {
					gotologin();
				}
			});
		}else {
			var tietrunk_number=$(data).find("item").attr("value");
			var gettext='';
			for(var i=1;i<=tietrunk_number;i++) {
				gettext+='&line_id='+i+'&id=810&id=816&id=817';
			}var geturl='/xml?method=gw.config.get'+gettext+'&tmp='+Math.random();
			$.get(geturl,function (data) {
				var stat=$(data).find('rsp').attr("stat");
				if(stat=="fail") {
					$(data).find('Error').each(function () {
						var code=$(this).attr('code');
						if(code==4) {
							//show_message("err",msg.cannotModify1);
							alert(msg.cannotModify1);
						}else if(code==5) {
							gotologin();
						}
					});
				}else {
					var ips=new Array();
					var total_ziyuan=new Array();
					$(data).find("item").each(function () {
						var line_id='';
						if(tietrunk_number=="1") {
							line_id=$(data).find("config").attr("line_id");
						}else {
							line_id=$(this).attr("line_id");
						}if($(this).attr("id")=="810") {
							ips[line_id]=$(this).attr("value");
							total_ziyuan[line_id]=line_id+"|"+$(this).attr("value");
						}
					});
					var array810=new Array();
					var array816=new Array();
					var array817=new Array();
					var array817_true=new Array();
					$(data).find("item").each(function () {
						var line_id='';
						if(tietrunk_number=="1") {
							line_id=$(data).find("config").attr("line_id");
						}else {
							line_id=$(this).attr("line_id");
						}if($(this).attr("id")=="810") {
							array810[line_id]=$(this).attr("value");
						}else if($(this).attr("id")=="816") {
							array816[line_id]=$(this).attr("value");
						}else if($(this).attr("id")=="817") {
							array817_true[line_id]=$(this).attr("value");
							var arrays=new Array();
							if($(this).attr("value").indexOf(",")>=0) {
								arrays=$(this).attr("value").split(",");
								var value817='';
								for(var i=0;i<arrays.length;i++) {
									if(i<arrays.length-1) {
										value817+=ips[arrays[i]]+',';
									}else {
										value817+=ips[arrays[i]];
									}
								}array817[line_id]=$.trim(value817);
							}else if($(this).attr("value")=="ALL") {
								array817[line_id]=$(this).attr("value");
							}else {
								arrays[0]=$(this).attr("value");
								var value817='';
								for(var i=0;i<arrays.length;i++) {
									if(i<arrays.length-1) {
										value817+=ips[arrays[i]]+',';
									}else {
										value817+=ips[arrays[i]];
									}
								}array817[line_id]=$.trim(value817);
							}
						}
					});
					var tablehtml='';
					for(var j=1;j<=tietrunk_number;j++) {
						if(array816[j]!=="") {
							if(j==1) {
								tablehtml+='<tr id="tr_'+j+'"><td class="td_tiet" id="td_'+j+'">&nbsp;'+array810[j]+'</td><td class="td_tiet">&nbsp;<input type="text" name="text" id="text_'+j+'" class="stepyidi-input" value="'+array816[j]+'"/></td><td class="td_tiet"><textarea name="textarea" id="textarea_'+j+'" truevalue="'+array817_true[j]+'">'+array817[j]+'</textarea></td><td class="td_tiet"><a href="#" name="fix_chuju" id="fix_'+j+'">'+tietrunkjs.cue14+'</a><span style="padding-left:10px;">&#160;</span><img src="delete.gif" width="14" height="13"/><a href="#" name="delete" id="delete_'+j+'">'+tietrunkjs.cue6+'</a></td></tr>';
							}else {
								tablehtml+='<tr id="tr_'+j+'"><td class="td_tiet" id="td_'+j+'">&nbsp;'+array810[j]+'</td><td class="td_tiet">&nbsp;<input type="text" name="text" id="text_'+j+'" class="stepyidi-input" value="'+array816[j]+'"/></td><td class="td_tiet"><textarea name="textarea" id="textarea_'+j+'" truevalue="'+array817_true[j]+'">'+array817[j]+'</textarea></td><td class="td_tiet"><a href="#" name="fix_chuju" id="fix_'+j+'">'+tietrunkjs.cue14+'</a><span style="padding-left:10px;">&#160;</span><img src="delete.gif" width="14" height="13"/><a href="#" name="delete" id="delete_'+j+'">'+tietrunkjs.cue6+'</a></td></tr>';
							}
						}
					}$("#ziyuan").html(tablehtml);
					$("input:text").each(function () {
						if($(this).attr("name")=="text") {
							var thisid=$(this).attr("id").split("_")[1];
							if($(this).val()=="") {
								$("#fix_"+thisid).attr("disabled",true);
							}else {
								$("#fix_"+thisid).attr("disabled",false);
							}
						}
					});
					$("[name=text]").blur(function () {
						var thisid=$(this).attr("id").split("_")[1];
						if($(this).val()=="") {
							$("#fix_"+thisid).attr("disabled",true);
						}else {
							$("#fix_"+thisid).attr("disabled",false);
						}
					});
					$("[name=add_ziyuan]").click(function () {
						var current_ziyuan=new Array();
						$("#ziyuan").find("tr").each(function () {
							var line_id=$(this).attr("id").split("_")[1];
							if($.trim($("#td_"+line_id).text())==total_ziyuan[line_id].split("|")[1]) {
								current_ziyuan[line_id]=line_id+"|"+$.trim($("#td_"+line_id).text());
							}else if($("#ziyuan_"+line_id).val()) {
								current_ziyuan[line_id]=line_id+"|"+total_ziyuan[line_id].split("|")[1];
							}
						});
						var array_ip=filter(total_ziyuan,current_ziyuan);
						var optionstr='';
						var current_id=0;
						for(var i=0;i<array_ip.length;i++) {
							if(array_ip[i]) {
								current_id=array_ip[i].split("|")[0];
								break;
							}
						}for(var i=0;i<array_ip.length;i++) {
							if(array_ip[i]) {
								optionstr+='<option value="'+array_ip[i].split("|")[0]+'">'+array_ip[i].split("|")[1]+'</option>';
							}
						}if(array_ip.length==0) {
							//show_message("err",tietrunkjs.cue15);
							alert(tietrunkjs.cue15);
						}else {
							var tabletietrunk='<tr id="tr_'+current_id+'"><td id="td_'+current_id+'" class="td_tiet"><select name="add_ziyuan" id="ziyuan_'+current_id+'">'+optionstr+'</select></td><td class="td_tiet">&nbsp;<input type="text" name="text" id="text_'+current_id+'" class="stepyidi-input"/></td><td class="td_tiet"><textarea name="textarea" id="textarea_'+current_id+'"  truevalue=""></textarea></td><td class="td_tiet"><a href="#" name="fix_chuju" id="fix_'+current_id+'">'+tietrunkjs.cue14+'</a><span style="padding-left:10px;">&#160;</span><img src="delete.gif" width="14" height="13"/><a href="#" name="delete" id="delete_'+current_id+'">'+tietrunkjs.cue6+'</a></td></tr>';
							$("#ziyuan").append(tabletietrunk);
						}$("[name=add_ziyuan]").change(function () {
							var thisid=$(this).val();
							var oldid=$(this).attr("id").split("_")[1];
							$(this).attr("id","ziyuan_"+thisid);
							$("#tr_"+oldid).attr("id","tr_"+thisid);
							$("#td_"+oldid).attr("id","td_"+thisid);
							$("#text_"+oldid).attr("id","text_"+thisid);
							$("#textarea_"+oldid).attr("id","textarea_"+thisid);
							$("#delete_"+oldid).attr("id","delete_"+thisid);
							$("#fix_"+oldid).attr("id","fix_"+thisid);
						});
						loadtextyidi("text_"+current_id,tietrunkjs.cue16);
						$("[name=delete]").click(function () {
							var number=$(this).attr("id").split("_")[1];
							$("#tr_"+number).hide();
							$("#td_"+number).text("");
							$("#text_"+number).attr("value","");
							$("#text_"+number).attr("truevalue","");
							$("#textarea_"+number).attr("value","");
							$("#textarea_"+number).attr("truevalue","");
						});
						$("[name=fix_chuju]").click(function () {
							var line_id=$(this).attr("id").split("_")[1];
							var tablehtml='<tr><td class="td_value"><span style="padding-left:15px;">&#160;</span><input type="checkbox" id="checkall"/>&#160;'+tietrunkjs.cue17+'<span style="padding-left:230px;">&#160;</span><input type="button" id="ok" value="'+tietrunkjs.cue18+'" class="submitbutton"/><span style="padding-left:20px;">&#160;</span><input type="button" id="cancel" value="'+tietrunkjs.cue19+'" class="submitbutton"/></td></tr>';
							for(var i=0;i<total_ziyuan.length;i++) {
								if(total_ziyuan[i]) {
									tablehtml+='<tr><td class="td_tiet"><input type="checkbox" name="checkline" id="check_'+total_ziyuan[i].split("|")[0]+'" trueid="'+total_ziyuan[i].split("|")[1]+'"><span style="padding-left:20px;">&#160;</span>'+total_ziyuan[i].split("|")[1]+'</td></tr>';
								}
							}$("#linetest").html(tablehtml);
							$("#checkall").click(function () {
								if($(this).attr("checked")) {
									$("[name=checkline]").attr("checked",true);
								}else {
									$("[name=checkline]").attr("checked",false);
								}
							});
							var current_value=$("#textarea_"+line_id).attr("truevalue");
							if(current_value.indexOf(",")>=0) {
								var loopvalue=current_value.split(",");
								for(var i=0;i<loopvalue.length;i++) {
									if(loopvalue[i]) {
										var thisid=loopvalue[i];
										$("#check_"+thisid).attr("checked",true);
									}
								}
							}else if(current_value=="ALL") {
								$("[name=checkline]").attr("checked",true);
							}else if(current_value) {
								$("#check_"+current_value).attr("checked",true);
							}$("#layer").show();
							$("#cancel").click(function () {
								$("#layer").hide();
							});
							$("#ok").click(function () {
								var result='';
								var str='';
								var num1=0;
								var num2=0;
								$(":checkbox").each(function () {
									num1++;
									if($(this).attr("name")=="checkline"&&$(this).attr("checked")) {
										result+=$(this).attr("id").split("_")[1]+",";
										str+=$(this).attr("trueid")+",";
										num2++;
									}
								});
								if(num1==num2) {
									$("#textarea_"+line_id).attr("truevalue","ALL");
									$("#textarea_"+line_id).text("ALL");
								}else {
									result=result.substr(0,result.length-1);
									if(result=="") {
										$("#textarea_"+line_id).attr("truevalue","ALL");
										$("#textarea_"+line_id).text("ALL");
									}else {
										str=str.substr(0,str.length-1);
										$("#textarea_"+line_id).attr("truevalue",result);
										$("#textarea_"+line_id).text(str);
									}
								}$("#layer").hide();
							});
						});
					});
					$("[name=fix_chuju]").click(function () {
						var line_id=$(this).attr("id").split("_")[1];
						var tablehtml='<tr><td align="right" class="td_name"><input type="checkbox" id="checkall"/>&#160;'+tietrunkjs.cue17+'<span style="padding-left:20px;">&#160;</span><input type="button" id="ok" value="'+tietrunkjs.cue18+'" class="submitbutton"/><span style="padding-left:20px;">&#160;</span><input type="button" id="cancel" value="'+tietrunkjs.cue19+'" class="submitbutton"/></td></tr>';
						for(var i=0;i<total_ziyuan.length;i++) {
							if(total_ziyuan[i]) {
								tablehtml+='<tr><td class="td_value"><input type="checkbox" name="checkline" id="check_'+total_ziyuan[i].split("|")[0]+'" trueid="'+total_ziyuan[i].split("|")[1]+'"><span style="padding-left:20px;">&#160;</span>'+total_ziyuan[i].split("|")[1]+'</td></tr>';
							}
						}$("#linetest").html(tablehtml);
						var current_value=$("#textarea_"+line_id).attr("truevalue");
						if(current_value.indexOf(",")>=0) {
							var loopvalue=current_value.split(",");
							for(var i=0;i<loopvalue.length;i++) {
								if(loopvalue[i]) {
									var thisid=loopvalue[i];
									$("#check_"+thisid).attr("checked",true);
								}
							}
						}else if(current_value=="ALL") {
							$("[name=checkline]").attr("checked",true);
						}else if(current_value=="NA") {
							$("[name=checkline]").attr("checked",false);
						}else if(current_value) {
							$("#check_"+current_value).attr("checked",true);
						}$("#layer").show();
						$("#cancel").click(function () {
							$("#layer").hide();
						});
						$("#checkall").click(function () {
							if($(this).attr("checked")) {
								$("[name=checkline]").attr("checked",true);
							}else {
								$("[name=checkline]").attr("checked",false);
							}
						});
						$("#ok").click(function () {
							var result='';
							var str='';
							var num1=0;
							var num2=0;
							$(":checkbox").each(function () {
								num1++;
								if($(this).attr("name")=="checkline"&&$(this).attr("checked")) {
									result+=$(this).attr("id").split("_")[1]+",";
									str+=$(this).attr("trueid")+",";
									num2++;
								}
							});
							if(num1==num2) {
								$("#textarea_"+line_id).attr("truevalue","ALL");
								$("#textarea_"+line_id).text("ALL");
							}else {
								result=result.substr(0,result.length-1);
								if(result=="") {
									$("#textarea_"+line_id).attr("truevalue","ALL");
									$("#textarea_"+line_id).text("ALL");
								}else {
									str=str.substr(0,str.length-1);
									$("#textarea_"+line_id).attr("truevalue",result);
									$("#textarea_"+line_id).text(str);
								}
							}$("#layer").hide();
						});
					});
					$("[name=delete]").click(function () {
						var number=$(this).attr("id").split("_")[1];
						$("#tr_"+number).hide();
						$("#td_"+number).text("");
						$("#text_"+number).attr("value","");
						$("#text_"+number).attr("truevalue","");
						$("#textarea_"+number).attr("value","");
						$("#textarea_"+number).attr("truevalue","");
					});
					$("[name=submit_ziyuan]").click(function () {
						var settext='';
						$("#ziyuan").find("tr").each(function () {
							var thisid=$(this).attr("id").split("_")[1];
							if($("#text_"+thisid).val()==tietrunkjs.cue16||$("#text_"+thisid).val()=="") {
								settext+="&line_id="+thisid+"&id816=";
							}else {
								settext+="&line_id="+thisid+"&id816="+$("#text_"+thisid).val();
							}if($("#textarea_"+thisid).text()!=="") {
								settext+="&id817="+$("#textarea_"+thisid).attr("truevalue");
							}else {
								settext+="&id817=";
							}
						});
						var url="method=gw.config.set"+settext+"&tmp="+Math.random();
						submitvalue(url,"3");
					});
				}
			});
		}
	});
}
function sync() {
	$.ajax({
		type:"POST",url:'xml?method=gw.command.set&action=tie_sync&tmp='+Math.random(),dataType:"xml",error:function (xml) {
			$(xml).find('Error').each(function () {
				var errortext=$(this).attr('msg');
				alert(errortext);
			});
		},success:function (xml) {
			var rspstat=$(xml).find("rsp").attr("stat");
			if(rspstat=="ok"||rspstat=="reboot"||rspstat=="restart") {
				//show_message("err",tietrunkjs.cue1);
				alert(tietrunkjs.cue1);
			}else {
				var errorcode=$(xml).find('Error').attr('code');
				if(errorcode=='5') {
					gotologin();
				}
			}
		}
	});
}
function broadcase() {
	$.ajax({
		type:"POST",url:'xml?method=gw.command.set&action=tie_broadcast&tmp='+Math.random(),dataType:"xml",error:function (xml) {
			$(xml).find('Error').each(function () {
				var errortext=$(this).attr('msg');
				alert(errortext);
			});
		},success:function (xml) {
			var rspstat=$(xml).find("rsp").attr("stat");
			if(rspstat=="ok"||rspstat=="reboot"||rspstat=="restart") {
				//show_message("err",tietrunkjs.cue1);
				alert(tietrunkjs.cue1);
			}else {
				var errorcode=$(xml).find('Error').attr('code');
				if(errorcode=='5') {
					gotologin();
				}
			}
		}
	});
}
function daochu() {
	$.ajax({
		type:"POST",url:'xml?method=gw.command.set&action=tie_upload&tmp='+Math.random(),dataType:"xml",error:function (xml) {
			$(xml).find('Error').each(function () {
				var errortext=$(this).attr('msg');
				alert(errortext);
			});
		},success:function (xml) {
			var stat=$(xml).find("rsp").attr("stat");
			if(stat=="ok"||stat=="restart"||stat=="reboot") {
				var downfilename="tietrunk.ini";
				window.location.href=downfilename;
			}else {
				//show_message("err",tietrunkjs.cue20);
				alert(tietrunkjs.cue20);
			}
		}
	});
}